package com.wys.mall.cart.vo;

import lombok.Data;
import org.apache.commons.collections.CollectionUtils;

import java.math.BigDecimal;
import java.util.List;

/**
 * @Package com.wys.mall.cart.vo
 * @Author charlin
 * @Version: v1.0
 * @Date 2021-07-089:15
 * @Copyright: 2021 www.wyscha.com Inc. All rights reserved.
 */
//@Data
public class Cart {

    /**
     * 购物项
     */
    private List<CartItem> items;
    /**
     * 商品数量
     */
    private Integer countNum;
    /**
     * 商品类型数量
     */
    private Integer countType;
    /**
     * 商品总价
     */
    private BigDecimal totalAmount;
    /**
     * 减免金格
     */
    private BigDecimal reduce = BigDecimal.ZERO;

    public List<CartItem> getItems() {
        return items;
    }

    public void setItems(List<CartItem> items) {
        this.items = items;
    }

    public Integer getCountNum() {
        int count = 0;
        if (CollectionUtils.isNotEmpty(this.items)) {
            for (CartItem item : this.items) {
                count += item.getCount();
            }
        }
        return count;
    }

//    public void setCountNum(Integer countNum) {
//        this.countNum = countNum;
//    }

    public Integer getCountType() {
        int count = 0;
        if (CollectionUtils.isNotEmpty(this.items)) {
            for (CartItem item : this.items) {
                count += 1;
            }
        }
        return count;
    }

//    public void setCountType(Integer countType) {
//        this.countType = countType;
//    }

    public BigDecimal getTotalAmount() {
        //1.获得购物项总价
        BigDecimal amount = BigDecimal.ZERO;
        if (CollectionUtils.isNotEmpty(this.items)) {
            for (CartItem item : this.items) {
                amount = amount.add(item.getTotalPrice());
            }
        }
        //2.减去优惠总价
        amount = amount.subtract(this.reduce);

        return amount;
    }

//    public void setTotalAmount(BigDecimal totalAmount) {
//        this.totalAmount = totalAmount;
//    }

    public BigDecimal getReduce() {
        return reduce;
    }

    public void setReduce(BigDecimal reduce) {
        this.reduce = reduce;
    }
}
